package com.gupaoedu.baifc.dynamicproxy.myproxy;

import com.gupaoedu.baifc.Person;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * projectName: baifc_proxy
 * packageName: com.gupaoedu.baifc.dynamicproxy.myproxy
 * Created: 2019/3/18.
 * Auther: baifc
 * Description:
 */
public class MyProxyMeipo implements MyInvocationHandler {



    private Person target;

    public Object getInstance(Person target)  {
        this.target = target;

        Class clazz = target.getClass();

        return MyProxy.newProxyInstance(new MyClassLoader(), clazz.getInterfaces(), this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object obj = method.invoke(target, args);
        after();
        return obj;
    }


    private void before() {
        System.out.println("开始物色...");
    }

    private void after() {
        System.out.println("物色OK");
    }
}
